package ooday03;

public class PolymorphicDemo {
    public static void main(String[] args) {
        /*
        Animal o = new Dog();
        Dog d = (Dog) o;
        Swim s = (Swim) o;
        //Fish f = (Fish) o;
        System.out.println(o  instanceof  Dog);
        System.out.println(o  instanceof  Swim);
        System.out.println(o instanceof Fish);
        if (o instanceof Fish){
            Fish f = (Fish) o;
        }else {
            System.out.println("o不是Fish类型");
        }
         */

        Animal[] animal = new Animal[5];
        animal[0] = new Dog("小黑",2,"黑");
        animal[1] = new Dog("小白",2,"白");
        animal[2] = new Chick("小红",3,"红");
        animal[3] = new Fish("小金",2,"金");
        animal[4] = new Fish("小花",1,"花");
        for (int i = 0;i<animal.length;i++){
            System.out.println(animal[i].name);
            animal[i].eat();
            animal[i].drink();
            if (animal[i] instanceof Dog){
                Dog dog = (Dog) animal[i];
                dog.lookHome();
            }
            if (animal[i] instanceof Chick){
                Chick chick = (Chick) animal[i];
                chick.layEggs();
            }
            if (animal[i] instanceof Swim){
                Swim s = (Swim) animal[i];
                s.swim();
            }
        }



        /*
        Master master = new Master();
        Dog dog = new Dog("小黑",2,"黑");
        Chick chick  = new Chick("小红",2,"红");
        Fish fish = new Fish("小金",2,"金");
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);

         */
        /*
        Dog dog = new Dog("小黑",2,"黑");
        Animal a1 = new Dog("小黑",2,"黑");
        Swim s1 = new Dog("小黑",2,"黑");

         */
    }
}
